package com.jyw.business.obstacles.domain.vo.web;

import com.jyw.common.constant.SysDictTypeConstant;
import com.jyw.business.obstacles.domain.ObsOrderFault;
import com.jyw.business.obstacles.domain.ObsOrderSend;
import com.jyw.common.annotation.Conversion;
import com.jyw.common.enums.ConversionType;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.DeptUtils;
import com.jyw.system.utils.FileUtils;
import com.jyw.system.utils.TeamUtils;
import com.jyw.system.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

import java.util.List;
import java.util.Optional;

/**
 * @author 沈峻
 * @ClassName AssistSubVO
 * @Description 协作子信息
 * @Date 2023/8/17 10:48
 **/
@ApiModel("协作子信息")
@Data
@NoArgsConstructor
@FieldNameConstants
public class AssistSubVO {

    @ApiModelProperty("协作人")
    @Conversion(value = ConversionType.USER,name = Fields.sendUserName)
    private Long sendUser;

    @ApiModelProperty("协作人名称")
    private String sendUserName;

    @ApiModelProperty("处理情况")
    @Conversion(value = ConversionType.DICT,dictType = SysDictTypeConstant.OBS_FAULT_STATE)
    private String currState;

    @ApiModelProperty("处理情况标签")
    private String currStateToName;

    @ApiModelProperty("协作事务")
    private String assistContent;

    @ApiModelProperty("协作附件")
    private List<SimpleFileVo> assistEnclosureList;

    public AssistSubVO(ObsOrderFault fault, List<ObsOrderSend> sendList) {
        setCurrState(fault.getCurrState());
        setAssistContent(fault.getAssistContent());
        setAssistEnclosureList(FileUtils.IdToFile(fault.getAssistEnclosureId()));
        Optional<ObsOrderSend> optional = sendList.stream().filter(send -> send.getOrderNum().equals(fault.getOrderNum())).findFirst();
        if(optional.isPresent()){
            ObsOrderSend send = optional.get();
            switch (send.getSendType()) {
                case 1:
                    setSendUserName(UserUtils.userIdToName(send.getSendUser()));
                    break;
                case 2:
                    setSendUserName(TeamUtils.teamIdToName(send.getSendTeam()));
                    break;
                case 3:
                    setSendUserName(DeptUtils.deptIdToName(send.getSendDept()));
                    break;
            }
        }
    }
}
